/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Transaction;

import Clases.CEmpleado;
import Clases.CVehiculo;
import Mantenimiento.Vehiculo;
import Modelo.Conection;
import Modelo.Functions;
import Modelo.Numero_a_Letra;
import Presentation.Main;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultCellEditor;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

/**
 *
 * @author Rudy
 */
public class AddTechnicalService extends javax.swing.JDialog {

    /**
     * Creates new form AddTechnicalService
     */
    Conection conection;
    DefaultTableModel modelo;
    Main main;
    Double tipoCambio=0.00;
    Numero_a_Letra NumLetra = new Numero_a_Letra();
    
    public AddTechnicalService(java.awt.Frame parent, boolean modal, Conection pconection,Main mainp,Double ptipoCambio) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(null);
        conection=pconection;
        conection.Conectar();
        gb_tipo_pago.add(rb_soles);
        gb_tipo_pago.add(rb_dolares);
        rb_soles.setSelected(true);
        try {
            conection.cargarComboEmpleado(cbc_empleado);
            AutoCompleteDecorator.decorate(cbc_empleado);
            conection.cargarComboVehiculo(cbc_placa);
            AutoCompleteDecorator.decorate(cbc_placa);
        } catch (SQLException ex) {
            Logger.getLogger(AddTechnicalService.class.getName()).log(Level.SEVERE, null, ex);
        }
        dc_fecha_st.setDate(new Date());
        modelo = (DefaultTableModel)tbl_tecnical_service.getModel();   
        JTextField textField = new JTextField();
        DefaultCellEditor dCE_tf=new DefaultCellEditor(textField);
        tbl_tecnical_service.getColumnModel().getColumn(4).setCellEditor(dCE_tf);
        tbl_tecnical_service.getColumnModel().getColumn(5).setCellEditor(dCE_tf);
        tbl_tecnical_service.getColumnModel().getColumn(8).setCellEditor(dCE_tf);
        tbl_tecnical_service.setRowHeight(25);
        main=mainp;
        tipoCambio=Double.valueOf(conection.get_tipoCambio());
        lbl_tipo_cambio.setText(tipoCambio.toString());
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        gb_tipo_pago = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        btn_insert_detallado = new javax.swing.JButton();
        btn_exit_st = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbl_tecnical_service = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        lbl_total_st = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        cbc_placa = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        cbc_empleado = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        dc_fecha_st = new com.toedter.calendar.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        tf_costo_total = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txa_descripcion = new javax.swing.JTextArea();
        jLabel5 = new javax.swing.JLabel();
        btn_add_tabla = new javax.swing.JButton();
        btn_clear = new javax.swing.JButton();
        btn_nuevo_vehiculo = new javax.swing.JButton();
        rb_soles = new javax.swing.JRadioButton();
        rb_dolares = new javax.swing.JRadioButton();
        btn_eliminar_st = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        lbl_tipo_cambio = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        tf_descuento = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Servicio Tecnico");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btn_insert_detallado.setText("Incluir Servicio ");
        btn_insert_detallado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_insert_detalladoActionPerformed(evt);
            }
        });

        btn_exit_st.setText("Cancelar");
        btn_exit_st.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_exit_stActionPerformed(evt);
            }
        });

        tbl_tecnical_service.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nro", "Codigo", "Placa", "Fecha", "Costo.B (US$.)", "% Dcto", "Costo.T (US$.)", "Empleado", "Descripcion"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true, true, true, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tbl_tecnical_service);
        tbl_tecnical_service.getColumnModel().getColumn(0).setMinWidth(40);
        tbl_tecnical_service.getColumnModel().getColumn(0).setPreferredWidth(40);
        tbl_tecnical_service.getColumnModel().getColumn(0).setMaxWidth(40);
        tbl_tecnical_service.getColumnModel().getColumn(1).setMinWidth(90);
        tbl_tecnical_service.getColumnModel().getColumn(1).setPreferredWidth(90);
        tbl_tecnical_service.getColumnModel().getColumn(1).setMaxWidth(90);
        tbl_tecnical_service.getColumnModel().getColumn(2).setMinWidth(100);
        tbl_tecnical_service.getColumnModel().getColumn(2).setPreferredWidth(100);
        tbl_tecnical_service.getColumnModel().getColumn(2).setMaxWidth(100);
        tbl_tecnical_service.getColumnModel().getColumn(3).setMinWidth(100);
        tbl_tecnical_service.getColumnModel().getColumn(3).setPreferredWidth(100);
        tbl_tecnical_service.getColumnModel().getColumn(3).setMaxWidth(100);
        tbl_tecnical_service.getColumnModel().getColumn(4).setMinWidth(90);
        tbl_tecnical_service.getColumnModel().getColumn(4).setPreferredWidth(90);
        tbl_tecnical_service.getColumnModel().getColumn(4).setMaxWidth(90);
        tbl_tecnical_service.getColumnModel().getColumn(5).setMinWidth(50);
        tbl_tecnical_service.getColumnModel().getColumn(5).setPreferredWidth(50);
        tbl_tecnical_service.getColumnModel().getColumn(5).setMaxWidth(50);
        tbl_tecnical_service.getColumnModel().getColumn(6).setMinWidth(90);
        tbl_tecnical_service.getColumnModel().getColumn(6).setPreferredWidth(90);
        tbl_tecnical_service.getColumnModel().getColumn(6).setMaxWidth(90);
        tbl_tecnical_service.getColumnModel().getColumn(7).setMinWidth(200);
        tbl_tecnical_service.getColumnModel().getColumn(7).setPreferredWidth(200);
        tbl_tecnical_service.getColumnModel().getColumn(7).setMaxWidth(200);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setText("Costo Total :");

        lbl_total_st.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        lbl_total_st.setText("0.00");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1165, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btn_insert_detallado, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 827, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lbl_total_st))
                            .addComponent(btn_exit_st, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(71, 71, 71))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_insert_detallado)
                    .addComponent(btn_exit_st))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(lbl_total_st))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        cbc_placa.setEditable(true);

        jLabel1.setText("Empleado :");

        cbc_empleado.setEditable(true);

        jLabel2.setText("Placa :");

        dc_fecha_st.setBackground(new java.awt.Color(255, 255, 255));
        dc_fecha_st.setEnabled(false);

        jLabel3.setText("Fecha :");

        jLabel4.setText("Costo Total :");

        txa_descripcion.setColumns(20);
        txa_descripcion.setLineWrap(true);
        txa_descripcion.setRows(5);
        txa_descripcion.setAutoscrolls(false);
        jScrollPane2.setViewportView(txa_descripcion);

        jLabel5.setText("Descripcion :");

        btn_add_tabla.setText("Agregar a Tabla");
        btn_add_tabla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_add_tablaActionPerformed(evt);
            }
        });

        btn_clear.setText("Limpiar Todo");
        btn_clear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_clearActionPerformed(evt);
            }
        });

        btn_nuevo_vehiculo.setText("Nuevo Vehiculo");
        btn_nuevo_vehiculo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_nuevo_vehiculoActionPerformed(evt);
            }
        });

        rb_soles.setText("Soles");

        rb_dolares.setText("Dolares");

        btn_eliminar_st.setText("Eliminar");
        btn_eliminar_st.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_eliminar_stActionPerformed(evt);
            }
        });

        jLabel8.setText("Tipo de Cambio: ");

        lbl_tipo_cambio.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lbl_tipo_cambio.setText("0.00");

        jLabel9.setText("Descuento :");

        tf_descuento.setText("0.00");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(90, 90, 90)
                                .addComponent(btn_clear)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addContainerGap(102, Short.MAX_VALUE)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel4)
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel2)
                                        .addComponent(jLabel3))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addGap(4, 4, 4)))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbc_empleado, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(btn_add_tabla)
                                        .addGap(26, 26, 26)
                                        .addComponent(btn_eliminar_st))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(tf_costo_total, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(dc_fecha_st, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lbl_tipo_cambio))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(cbc_placa, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(btn_nuevo_vehiculo)))
                                .addGap(50, 50, 50)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel9))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(182, 182, 182)
                        .addComponent(rb_soles)
                        .addGap(18, 18, 18)
                        .addComponent(rb_dolares)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 426, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_descuento, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(79, 79, 79))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btn_clear)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(cbc_empleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbc_placa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)
                            .addComponent(btn_nuevo_vehiculo))
                        .addGap(20, 20, 20)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dc_fecha_st, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)))
                    .addComponent(jScrollPane2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rb_dolares)
                    .addComponent(rb_soles))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_costo_total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel8)
                    .addComponent(lbl_tipo_cambio)
                    .addComponent(jLabel9)
                    .addComponent(tf_descuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_add_tabla)
                    .addComponent(btn_eliminar_st))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_insert_detalladoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_insert_detalladoActionPerformed
        // TODO add your handling code here:
        if(modelo.getRowCount()!=0)
        {
            for (int i = 0; i < tbl_tecnical_service.getRowCount(); i++) {
                ArrayList values = new ArrayList();
                //values.add(Integer.valueOf(String.valueOf(tbl_tecnical_service.getValueAt(i, 0)).split("-")[1]));
                values.add(String.valueOf(tbl_tecnical_service.getValueAt(i, 2)));
                values.add(String.valueOf(tbl_tecnical_service.getValueAt(i, 3)));
                values.add(Double.valueOf(tbl_tecnical_service.getValueAt(i, 4).toString()));
                values.add(Double.valueOf(tbl_tecnical_service.getValueAt(i, 5).toString()));
                values.add(Double.valueOf(tbl_tecnical_service.getValueAt(i, 6).toString()));
                values.add(String.valueOf(tbl_tecnical_service.getValueAt(i, 7)));
                values.add(String.valueOf(tbl_tecnical_service.getValueAt(i, 8)));
                values.add(main.getDni());

                ArrayList columnas = new ArrayList();
                //columnas.add("id_servicio_tecnico");
                columnas.add("placa");
                columnas.add("fecha");
                columnas.add("costobruto");
                columnas.add("porcentaje_descuento");
                columnas.add("costototal");
                columnas.add("dni_empleado"); 
                columnas.add("descripcion"); 
                columnas.add("dni"); 

                conection.insert(columnas, values, "tservicio_tecnico");
                
                Object D[] ={Venta.tbl_venta.getRowCount()+1,tbl_tecnical_service.getValueAt(i, 1),tbl_tecnical_service.getValueAt(i, 8),"-","-",tbl_tecnical_service.getValueAt(i, 4),tbl_tecnical_service.getValueAt(i, 5),tbl_tecnical_service.getValueAt(i, 6),"-"};
                Venta.getModelo().addRow(D);  
            }  
            
            //Calcular Subtotales
            int fila = Venta.getModelo().getRowCount();
            double precio_venta=0;
            double valor_bruto=0;
            double descuento=0;
            double valor_neto=0;
            double recargos=0;
            double valor_venta=0;
            double igv=0;
            for (int i = 0; i < fila; i++) {
                double vb=0;
                double dcto=0;
                if(!((Venta.getModelo().getValueAt(i, 1).toString().split("-"))[0]).equals("ST"))
                {
                    vb=Integer.parseInt(Venta.getModelo().getValueAt(i, 3).toString())*Double.parseDouble(Venta.getModelo().getValueAt(i, 4).toString());
                    dcto=vb*(Double.parseDouble(Venta.getModelo().getValueAt(i, 6).toString())/100);
                    Venta.getModelo().setValueAt(vb, i, 5);
                    Venta.getModelo().setValueAt(Functions.round(vb-dcto,2), i, 7);
                }
                else
                {   
                    vb=Double.parseDouble(Venta.getModelo().getValueAt(i, 5).toString());
                    dcto=vb*(Double.parseDouble(Venta.getModelo().getValueAt(i, 6).toString())/100);
                }
                Venta.getModelo().setValueAt(i+1, i, 0);
                valor_bruto+=vb;
                descuento+=dcto;
                valor_neto+=vb-dcto;
                recargos+=0;
                valor_venta+=vb-dcto;            
                //precio_venta += (Double.parseDouble(modelo.getValueAt(i, 7).toString()));
            }
            igv=valor_venta*0.18;
            precio_venta=valor_venta+igv;
            
            Venta.lbl_precio_venta.setText(String.valueOf(Functions.round(precio_venta,2)));
            Venta.lbl_valor_bruto.setText(String.valueOf(Functions.round(valor_bruto,2)));
            Venta.lbl_descuento.setText(String.valueOf(Functions.round(descuento,2)));
            Venta.lbl_valor_neto.setText(String.valueOf(Functions.round(valor_neto,2)));
            Venta.lbl_recargos.setText(String.valueOf(Functions.round(recargos,2)));
            Venta.lbl_valor_venta.setText(String.valueOf(Functions.round(valor_venta,2)));
            Venta.lbl_igv.setText(String.valueOf(Functions.round(igv,2)));
            Venta.lbl_num_letra_en.setText(NumLetra.Convertir(String.valueOf(Functions.round(precio_venta,2)),true));
            this.setVisible(false);
            
            this.setVisible(false);
        }
        else
        {
            JOptionPane.showMessageDialog(this,"Error.\nNo se Registro ningun servicio.", "ATENCION", JOptionPane.INFORMATION_MESSAGE);
            this.setVisible(false);
        }
    }//GEN-LAST:event_btn_insert_detalladoActionPerformed

    private void btn_exit_stActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_exit_stActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_btn_exit_stActionPerformed

    private void btn_clearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_clearActionPerformed
        // TODO add your handling code here:
        try {
            conection.cargarComboEmpleado(cbc_empleado);
            AutoCompleteDecorator.decorate(cbc_empleado);
            conection.cargarComboVehiculo(cbc_placa);
            AutoCompleteDecorator.decorate(cbc_placa);
        } catch (SQLException ex) {
            Logger.getLogger(AddTechnicalService.class.getName()).log(Level.SEVERE, null, ex);
        }
        tf_costo_total.setText(null);
        txa_descripcion.setText(null);
        rb_soles.setSelected(true);      
    }//GEN-LAST:event_btn_clearActionPerformed

    private void btn_add_tablaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_add_tablaActionPerformed
        // TODO add your handling code here:
        boolean error=false;
        if(tf_costo_total.getText().equals(""))
        {error=true;
           JOptionPane.showMessageDialog(this,"Error.\nCampo del Costo vacio.", "ATENCION", JOptionPane.INFORMATION_MESSAGE);
        }
        if(txa_descripcion.getText().equals(""))
        {error=true;
           JOptionPane.showMessageDialog(this,"Error.\nCampo de Descripcion vacio.", "ATENCION", JOptionPane.INFORMATION_MESSAGE);
        }        
        if(!error)
        {
        CEmpleado empleado = (CEmpleado)cbc_empleado.getSelectedItem();
        CVehiculo vehiculo = (CVehiculo)cbc_placa.getSelectedItem();
        int id_st=conection.getUltimoId("id_servicio_tecnico"," tservicio_tecnico ");
        //System.out.println(id_st);
        Double costoBruto=Double.valueOf(tf_costo_total.getText());
        if(rb_soles.isSelected()){costoBruto=costoBruto/ Double.valueOf(lbl_tipo_cambio.getText());} 
        Double descuento=Double.valueOf(tf_descuento.getText());
        Double costoTotal=costoBruto-costoBruto*(descuento/100);
        int filas=tbl_tecnical_service.getRowCount();
        Object D[] ={filas+1,"ST-"+(id_st+filas+1),vehiculo.getPlaca(),new SimpleDateFormat("yyyy-MM-dd").format(dc_fecha_st.getDate()),Functions.round(costoBruto, 2) ,Functions.round(descuento, 2),Functions.round(costoTotal, 2),empleado.getDni_empleado(),txa_descripcion.getText()};
        modelo.addRow(D);}   
        calcularTotal();
    }//GEN-LAST:event_btn_add_tablaActionPerformed

    private void btn_nuevo_vehiculoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_nuevo_vehiculoActionPerformed
        // TODO add your handling code here:
        AddVehiculo vehiculo= new AddVehiculo(null, rootPaneCheckingEnabled);
        vehiculo.setVisible(true);
    }//GEN-LAST:event_btn_nuevo_vehiculoActionPerformed

    private void btn_eliminar_stActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_eliminar_stActionPerformed
        // TODO add your handling code here:
        try {
            modelo.removeRow(tbl_tecnical_service.getSelectedRow());
            int id_st=conection.getUltimoId("id_servicio_tecnico"," tservicio_tecnico ");
            for (int i = 0; i < tbl_tecnical_service.getRowCount(); i++) {
                tbl_tecnical_service.setValueAt(i+1, i, 0);
                tbl_tecnical_service.setValueAt("ST-"+(id_st+i+1), i, 1);
            }
        } catch (Exception e) {
           JOptionPane.showMessageDialog(this,"Error.\nSeleccion fila a eliminar.", "ATENCION", JOptionPane.INFORMATION_MESSAGE);
        }        
        calcularTotal();
    }//GEN-LAST:event_btn_eliminar_stActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AddTechnicalService.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AddTechnicalService.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AddTechnicalService.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AddTechnicalService.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                AddTechnicalService dialog = new AddTechnicalService(new javax.swing.JFrame(), true, null, null, Double.NaN);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_add_tabla;
    private javax.swing.JButton btn_clear;
    private javax.swing.JButton btn_eliminar_st;
    private javax.swing.JButton btn_exit_st;
    private javax.swing.JButton btn_insert_detallado;
    private javax.swing.JButton btn_nuevo_vehiculo;
    public static javax.swing.JComboBox cbc_empleado;
    public static javax.swing.JComboBox cbc_placa;
    public static com.toedter.calendar.JDateChooser dc_fecha_st;
    private javax.swing.ButtonGroup gb_tipo_pago;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbl_tipo_cambio;
    private javax.swing.JLabel lbl_total_st;
    private javax.swing.JRadioButton rb_dolares;
    private javax.swing.JRadioButton rb_soles;
    private javax.swing.JTable tbl_tecnical_service;
    private javax.swing.JTextField tf_costo_total;
    private javax.swing.JTextField tf_descuento;
    private javax.swing.JTextArea txa_descripcion;
    // End of variables declaration//GEN-END:variables
    public void calcularTotal()
    {
        Double total=0.00;
        for (int i = 0; i < tbl_tecnical_service.getRowCount(); i++) {
            total+=Double.valueOf(tbl_tecnical_service.getValueAt(i, 6).toString());
        }
        lbl_total_st.setText(total.toString());
    }
}
